package org.yuangu.privacyfinance.activities.viewmodel;

import android.app.Application;

import com.privacy.accountmgr.R;

import org.yuangu.privacyfinance.activities.adapter.AccountWrapper;
import org.yuangu.privacyfinance.domain.FinanceDatabase;
import org.yuangu.privacyfinance.domain.model.Account;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Transformations;

public class AccountsViewModel extends BaseViewModel {
    private LiveData<List<AccountWrapper>> accounts;

    public AccountsViewModel(@NonNull Application application) {
        super(application);
        setNavigationDrawerId(R.id.nav_account);
        setTitle(R.string.activity_accounts_title);
        accounts = Transformations.map(FinanceDatabase.getInstance().accountDao().getAll(), input -> {
            List<AccountWrapper> wrappers = new ArrayList<>();
            for (Account account : input) {
                wrappers.add(new AccountWrapper(account));
            }
            return wrappers;
        });
    }

    public LiveData<List<AccountWrapper>> getAccounts() {
        return accounts;
    }

    public void setAccounts(LiveData<List<AccountWrapper>> accounts) {
        this.accounts = accounts;
    }
}

